#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <mqueue.h>
#include <sys/stat.h>


#define mqueue_name "/GATEWAY_POOL_QUEUE"
int main(int argc, char const *argv[])
{
   
    //1 创建队列
    struct mq_attr attr;
    attr.mq_msgsize = 256;
    attr.mq_maxmsg = 10;

    mqd_t mqd = mq_open(mqueue_name, O_CREAT | O_RDWR, 0666, &attr);


    //2 发送消息 
    int ret= mq_send(mqd, "hello world", 12, 0);
    if(ret == -1)
    {
        perror("mq_send failed");
        return -1;
    }


    //3 接收消息 
    char buf[256];
    int size = mq_receive(mqd, buf, 256, NULL);
    if(size == -1)
    {
        perror("mq_receive failed");
        return -1;
    }
    else
    {
        printf("receive message: %s\n", buf);
    }


    //4 关闭队列
    mq_close(mqd);

    //5 删除队列
   // mq_unlink(mqueue_name);

    return 0;
}
